﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using MySql.Data.Types;

namespace Gui.Functies.Takenlijst_popups
{
    public partial class Edittaak2 : Form
    {
        int projectID;
        string taaknaam;
        int taakID;
        string nieuwenaam;

        public Edittaak2()
        {
            
        }

        public Edittaak2(int projectnummer,string taskname,int taaknummer)
        {
            projectID = projectnummer;
            taaknaam = taskname;
            taakID = taaknummer;
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            nieuwenaam = textBox1.Text;
            

            if (nieuwenaam != "")
            {
                saveTask();
            }
            else
            {
                MessageBox.Show("Niet alle velden zijn ingevuld!");
            }

        }

        public void saveTask()
        {

            string connString = "Server=qq-design.com;Port=3306;Database=cookicom0;Uid=cookicom0;pwd=pizzahut91";
            MySqlConnection grabConnection = new MySqlConnection(connString);
            MySqlCommand command = grabConnection.CreateCommand();
            command.CommandText = "Update taken SET Taak=@nieuwenaam WHERE TaakID=@taakid";
            command.Parameters.Add(new MySqlParameter("nieuwenaam", nieuwenaam));
            command.Parameters.Add(new MySqlParameter("taakid", taakID));
            try
            {
               grabConnection.Open();
               command.ExecuteNonQuery();
            }
            catch (MySqlException e)
            {
                MessageBox.Show(e.ToString());
            }
            finally
            {
                grabConnection.Close();
                MessageBox.Show("Taak succesvol opgeslagen!");
                this.Close();
            }
        }

        private void Edittaak2_Load(object sender, EventArgs e)
        {

        }

        private void label3_Click(object sender, EventArgs e)
        {
            label3.Text = taaknaam;
        }
    }
}
